<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-focus v-color="'pink'">
        <input type="text" v-focus v-color>
        <input type="text" v-focus v-color>
        <div v-fontweight="900" v-fontsize="'30px'">{{dt}}</div>

    </div>
    <script>
        Vue.directive("focus", {
            bind: function (el) { //绑定到元素上时

            },
            inserted: function (el) { //插入到dom中的时候
                el.focus() //只有插入dom之后才能获取焦点
            },
            update: function (el) { //vNode更新的时候

            }
        })


        Vue.directive("color", {
             bind: function (el, binding) {
                el.style.color = "red" //所有
                el.style.color = binding.value //自定义颜色 
                console.log(binding.value); //pink
                console.log(binding.expression) //'pink'
            }
        })

        new Vue({
            el: "#app",
            data: {
                dt: new Date()

            },
            directives: {  //自定义私有指令
                'fontweight': {
                    bind: function (el, binding) {
                        el.style.fontWeight = binding.value;
                    }
                },
                'fontsize':{
                    bind:function(el,binding){
                        el.style.fontSize=parseInt(binding.value)+"px"
                    }
                }

            }
        })
    </script>
</body>

</html>